COVID-19. Spatial analysis & geospatial data science in Python

Learn how to progress and visualize geospatial data and perform spatial analysis using python.

Geospatial data sicence is a subset of data science that focuses on spactial data and its unique techniques. In this, we are going to perfomr spatial analysis and trying to find insights from spatial data. In this project, we lay the foundation for a career in Geospatial Data Science. You will get hands-on Geopy, plotly, etc the workhorse of geospatial data science Python libraries.

The topics covered in this project widely touch on some of the most used spatial technique in geospatial data science. We will be learning how read spatial data, manipulate and process spatial data using Pandas, and perform some spatial operations.

In [1]:
import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt
In [2]:
!pip install plotly
Requirement already satisfied: plotly in c:\users\pauli\anaconda3\lib\site-packages (4.11.0)
Requirement already satisfied: six in c:\users\pauli\anaconda3\lib\site-packages (from plotly) (1.15.0)
Requirement already satisfied: retrying>=1.3.3 in c:\users\pauli\anaconda3\lib\site-packages (from plotly) (1.3.3)
In [3]:
import plotly.express as px
In [4]:
dir(px)
Out[4]:
['Constant',
 'IdentityMap',
 'NO_COLOR',
 'Range',
 '__all__',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__path__',
 '__spec__',
 '_chart_types',
 '_core',
 '_doc',
 '_imshow',
 '_special_inputs',
 'absolute_import',
 'area',
 'bar',
 'bar_polar',
 'box',
 'choropleth',
 'choropleth_mapbox',
 'colors',
 'data',
 'defaults',
 'density_contour',
 'density_heatmap',
 'density_mapbox',
 'funnel',
 'funnel_area',
 'get_trendline_results',
 'histogram',
 'imshow',
 'imshow_utils',
 'line',
 'line_3d',
 'line_geo',
 'line_mapbox',
 'line_polar',
 'line_ternary',
 'optional_imports',
 'parallel_categories',
 'parallel_coordinates',
 'pd',
 'pie',
 'png',
 'scatter',
 'scatter_3d',
 'scatter_geo',
 'scatter_mapbox',
 'scatter_matrix',
 'scatter_polar',
 'scatter_ternary',
 'set_mapbox_access_token',
 'strip',
 'sunburst',
 'timeline',
 'treemap',
 'violin']
In [5]:
import plotly
import plotly.graph_objs as go
from plotly import tools
from plotly.offline import init_notebook_mode, plot, iplot
In [6]:
dir(plotly)
Out[6]:
['__version__',
 'colors',
 'data',
 'graph_objects',
 'graph_objs',
 'io',
 'offline',
 'tools',
 'utils']
In [7]:
print(plotly.__version__)
4.11.0
In [8]:
current_data=pd.read_csv('https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv')
current_data.head(120)
Out[8]:
Date Country Confirmed Recovered Deaths
0 2020-01-22 Afghanistan 0 0 0
1 2020-01-23 Afghanistan 0 0 0
2 2020-01-24 Afghanistan 0 0 0
3 2020-01-25 Afghanistan 0 0 0
4 2020-01-26 Afghanistan 0 0 0
... ... ... ... ... ...
115 2020-05-16 Afghanistan 6402 745 168
116 2020-05-17 Afghanistan 6664 778 169
117 2020-05-18 Afghanistan 7072 801 173
118 2020-05-19 Afghanistan 7653 850 178
119 2020-05-20 Afghanistan 8145 930 187

120 rows × 5 columns

In [9]:
current_data.tail(10)
Out[9]:
Date Country Confirmed Recovered Deaths
52154 2020-10-14 Zimbabwe 8055 7640 231
52155 2020-10-15 Zimbabwe 8075 7669 231
52156 2020-10-16 Zimbabwe 8099 7673 231
52157 2020-10-17 Zimbabwe 8110 7673 231
52158 2020-10-18 Zimbabwe 8147 7678 231
52159 2020-10-19 Zimbabwe 8159 7683 232
52160 2020-10-20 Zimbabwe 8187 7692 233
52161 2020-10-21 Zimbabwe 8215 7725 236
52162 2020-10-22 Zimbabwe 8242 7742 236
52163 2020-10-23 Zimbabwe 8257 7771 236

Choropleth Maps

Show interval dataa as colours. They are shaded in using one colour, where the darker shades represent high numbers and the lighter shades represent low numbers. A choropleth map needs a key to explain what the different shapes mean.

How do you read a choropleth map?

  • First read the instruction and colour legend/key to understand what the shading means.
  • Look for the regions with the largest value shades.
  • The look for the lighter colours to see the low values.
  • Look out for any significant regional patterns.
In [10]:
fig=px.choropleth(current_data, locations='Country', locationmode='country names', color='Confirmed', animation_frame='Date')
In [11]:
fig.update_layout(title=('Choropleth Map of confirmed cases Till today'), template='plotly_dark')
fig.show()
In [12]:
fig=px.choropleth(current_data, locations='Country', locationmode='country names', color='Confirmed', animation_frame='Date', scope='europe')
fig.update_layout(title='Choropleth Map of confirmed cases Till today', template='plotly_dark')
fig.show()
In [13]:
fig=px.choropleth(current_data, locations='Country', locationmode='country names', color='Confirmed', animation_frame='Date', scope='asia')
fig.update_layout(title='Choropleth Map of confirmed cases Till today', template='plotly_dark')
fig.show()
In [14]:
fig=px.choropleth(current_data, locations='Country', locationmode='country names', color='Confirmed', animation_frame='Date', scope='north america')
fig.update_layout(title='Choropleth Map of confirmed cases Till today', template='plotly_dark')
fig.show()
In [15]:
fig=px.choropleth(current_data, locations='Country', locationmode='country names', color='Confirmed', animation_frame='Date', scope='south america')
fig.update_layout(title='Choropleth Map of confirmed cases Till today', template='plotly_dark')
fig.show()

How to create Geographical Scatter Plot.

  • We provides data point (which is represented as a maker point) on the map.
  • We have to provide location which is represented by the (Longitude) and (Latitude).
In [16]:
fig=px.scatter_geo(current_data, locations='Country', locationmode='country names', color='Confirmed', size='Confirmed', hover_name='Country', animation_frame='Date', title='Spread over time')
fig.update(layout_template='plotly_dark')
fig.show()
In [17]:
current_data.columns
Out[17]:
Index(['Date', 'Country', 'Confirmed', 'Recovered', 'Deaths'], dtype='object')
In [18]:
fig=px.choropleth(current_data, locations='Country', locationmode='country names', color='Recovered', animation_frame='Date')
fig.update_layout(title='Choropleth Map of Recovered cases Till today', template='plotly_dark')
fig.show()
In [19]:
fig=px.choropleth(current_data, locations='Country', locationmode='country names', color='Recovered', animation_frame='Date', scope='europe')
fig.update_layout(title='Choropleth Map of Recovered cases Till today', template='plotly_dark')
fig.show()
In [20]:
fig=px.choropleth(current_data, locations='Country', locationmode='country names', color='Recovered', animation_frame='Date', scope='north america')
fig.update_layout(title='Choropleth Map of Recovered cases Till today', template='plotly_dark')
fig.show()
In [21]:
fig=px.scatter_geo(current_data, locations='Country', locationmode='country names', color='Recovered', size='Recovered', hover_name='Country', animation_frame='Date', title='Recovery over time')
fig.update(layout_template='plotly_dark')
fig.show()
In [22]:
current_data.columns
Out[22]:
Index(['Date', 'Country', 'Confirmed', 'Recovered', 'Deaths'], dtype='object')
In [23]:
fig=px.choropleth(current_data, locations='Country', locationmode='country names', color='Deaths', animation_frame='Date')
fig.update_layout(title='Choropleth Map of Deaths cases Till today', template='plotly_dark')
fig.show()
In [24]:
fig=px.scatter_geo(current_data, locations='Country', locationmode='country names', color='Deaths', size='Deaths', hover_name='Country', animation_frame='Date', title='Deaths over time')
fig.update(layout_template='plotly_dark')
fig.show()
In [25]:
fig=px.choropleth(current_data, locations='Country', locationmode='country names', color='Deaths', animation_frame='Date', scope='europe')
fig.update_layout(title='Choropleth Map of Recovered cases Till today', template='plotly_dark')
fig.show()
In [26]:
fig=px.choropleth(current_data, locations='Country', locationmode='country names', color='Deaths', animation_frame='Date', scope='north america')
fig.update_layout(title='Choropleth Map of Recovered cases Till today', template='plotly_dark')
fig.show()
In [27]:
fig=px.choropleth(current_data, locations='Country', locationmode='country names', color='Deaths', animation_frame='Date', scope='asia')
fig.update_layout(title='Choropleth Map of Recovered cases Till today', template='plotly_dark')
fig.show()
In [28]:
fig=px.choropleth(current_data, locations='Country', locationmode='country names', color='Deaths', animation_frame='Date', scope='south america')
fig.update_layout(title='Choropleth Map of Recovered cases Till today', template='plotly_dark')
fig.show()
In [29]:
!pip install geopy
Requirement already satisfied: geopy in c:\users\pauli\anaconda3\lib\site-packages (2.0.0)
Requirement already satisfied: geographiclib<2,>=1.49 in c:\users\pauli\anaconda3\lib\site-packages (from geopy) (1.50)
In [30]:
import geopy
from geopy.geocoders import Nominatim
In [31]:
geolocator=Nominatim(user_agent='app')
In [32]:
location=geolocator.geocode('Eiffel Tower')
print(location.latitude, location.longitude)
48.858260200000004 2.2944990543196795
In [33]:
df=current_data.copy()
In [34]:
df.head()
Out[34]:
Date Country Confirmed Recovered Deaths
0 2020-01-22 Afghanistan 0 0 0
1 2020-01-23 Afghanistan 0 0 0
2 2020-01-24 Afghanistan 0 0 0
3 2020-01-25 Afghanistan 0 0 0
4 2020-01-26 Afghanistan 0 0 0
In [35]:
df[df['Country']=='Afghanistan']
Out[35]:
Date Country Confirmed Recovered Deaths
0 2020-01-22 Afghanistan 0 0 0
1 2020-01-23 Afghanistan 0 0 0
2 2020-01-24 Afghanistan 0 0 0
3 2020-01-25 Afghanistan 0 0 0
4 2020-01-26 Afghanistan 0 0 0
... ... ... ... ... ...
271 2020-10-19 Afghanistan 40287 33760 1497
272 2020-10-20 Afghanistan 40357 33790 1499
273 2020-10-21 Afghanistan 40510 33824 1501
274 2020-10-22 Afghanistan 40626 33831 1505
275 2020-10-23 Afghanistan 40687 34010 1507

276 rows × 5 columns

In [36]:
df2=df.groupby(['Country'])[['Confirmed','Recovered','Deaths']].max().reset_index()
df2.head(10)
Out[36]:
Country Confirmed Recovered Deaths
0 Afghanistan 40687 34010 1507
1 Albania 18556 10466 469
2 Algeria 55630 38788 1897
3 Andorra 4038 2729 69
4 Angola 8829 3384 265
5 Antigua and Barbuda 122 107 3
6 Argentina 1069368 866695 28338
7 Armenia 73310 50276 1145
8 Australia 27495 25173 905
9 Austria 74415 55195 954
In [37]:
lat_lon=[]
geolocator=Nominatim(user_agent='app')
for location in df2['Country']:
    location=geolocator.geocode(location)
    if location is None:
        lat_lon.append(np.nan)
    else:
        geo=(location.latitude, location.longitude)
        lat_lon.append(geo)
In [38]:
lat_lon
Out[38]:
[(33.7680065, 66.2385139),
 (41.000028, 19.9999619),
 (28.0000272, 2.9999825),
 (42.5407167, 1.5732033),
 (-11.8775768, 17.5691241),
 (17.2234721, -61.9554608),
 (-34.9964963, -64.9672817),
 (40.7696272, 44.6736646),
 (-24.7761086, 134.755),
 (47.2000338, 13.199959),
 (40.3936294, 47.7872508),
 (24.7736546, -78.0000547),
 (26.1551249, 50.5344606),
 (24.4768783, 90.2932426),
 (13.1500331, -59.5250305),
 (53.4250605, 27.6971358),
 (50.6402809, 4.6667145),
 (16.8259793, -88.7600927),
 (9.5293472, 2.2584408),
 (27.549511, 90.5119273),
 (-17.0568696, -64.9912286),
 (44.3053476, 17.5961467),
 (-23.1681782, 24.5928742),
 (-10.3333333, -53.2),
 (4.4137155, 114.5653908),
 (42.6073975, 25.4856617),
 (12.0753083, -1.6880314),
 (17.1750495, 95.9999652),
 (-3.3634357, 29.8870575),
 (16.0000552, -24.0083947),
 (13.5066394, 104.869423),
 (4.6125522, 13.1535811),
 (61.0666922, -107.9917071),
 (7.0323598, 19.9981227),
 (15.6134137, 19.0156172),
 (-31.7613365, -71.3187697),
 (35.000074, 104.999927),
 (2.8894434, -73.783892),
 (-12.2045176, 44.2832964),
 (-0.7264327, 15.6419155),
 (-2.9814344, 23.8222636),
 (10.2735633, -84.0739102),
 (7.9897371, -5.5679458),
 (45.5643442, 17.0118954),
 (23.0131338, -80.8328748),
 (34.9823018, 33.1451285),
 (49.8167003, 15.4749544),
 (55.670249, 10.3333283),
 (53.8953584, 27.5554078),
 (11.8145966, 42.8453061),
 (19.0974031, -70.3028026),
 (19.0974031, -70.3028026),
 (-1.3397668, -79.3666965),
 (26.2540493, 29.2675469),
 (13.8000382, -88.9140683),
 (1.613172, 10.5170357),
 (15.9500319, 37.9999668),
 (58.7523778, 25.3319078),
 (-26.5624806, 31.3991317),
 (10.2116702, 38.6521203),
 (-18.1239696, 179.0122737),
 (63.2467777, 25.9209164),
 (46.603354, 1.8883335),
 (-0.8999695, 11.6899699),
 (13.470062, -15.4900464),
 (32.3293809, -83.1137366),
 (51.0834196, 10.4234469),
 (8.0300284, -1.0800271),
 (38.9953683, 21.9877132),
 (12.1360374, -61.6904045),
 (15.6356088, -89.8988087),
 (10.7226226, -10.7083587),
 (12.100035, -14.9000214),
 (4.8417097, -58.6416891),
 (19.1399952, -72.3570972),
 (38.9247244, -77.06572732690151),
 (15.2572432, -86.0755145),
 (47.1817585, 19.5060937),
 (64.9841821, -18.1059013),
 (22.3511148, 78.6677428),
 (-2.4833826, 117.8902853),
 (32.6475314, 54.5643516),
 (33.0955793, 44.1749775),
 (52.865196, -7.9794599),
 (31.5313113, 34.8667654),
 (42.6384261, 12.674297),
 (18.1152958, -77.1598454610168),
 (36.5748441, 139.2394179),
 (31.1667049, 36.941628),
 (47.2286086, 65.2093197),
 (1.4419683, 38.4313975),
 (36.638392, 127.6961188),
 (42.5869578, 20.9021231),
 (29.2733964, 47.4979476),
 (41.5089324, 74.724091),
 (20.0171109, 103.378253),
 (56.8406494, 24.7537645),
 (33.8750629, 35.843409),
 (-29.6039267, 28.3350193),
 (5.7499721, -9.3658524),
 (26.8234472, 18.1236723),
 (47.1416307, 9.5531527),
 (55.3500003, 23.7499997),
 (49.8158683, 6.1296751),
 (52.4387696, 4.8185293),
 (-18.9249604, 46.4416422),
 (-13.2687204, 33.9301963),
 (4.5693754, 102.2656823),
 (4.7064352, 73.3287853),
 (16.3700359, -2.2900239),
 (35.8885993, 14.4476911),
 (20.2540382, -9.2399263),
 (-20.2759451, 57.5703566),
 (22.5000485, -100.0000375),
 (47.2879608, 28.5670941),
 (43.7323492, 7.4276832),
 (46.8250388, 103.8499736),
 (42.9868853, 19.5180992),
 (31.1728205, -7.3362482),
 (-19.302233, 34.9144977),
 (-23.2335499, 17.3231107),
 (28.1083929, 84.0917139),
 (52.5001698, 5.7480821),
 (-41.5000831, 172.8344077),
 (12.6090157, -85.2936911),
 (17.7356214, 9.3238432),
 (9.6000359, 7.9999721),
 (41.6171214, 21.7168387),
 (60.5000209, 9.0999715),
 (21.0000287, 57.0036901),
 (30.3308401, 71.247499),
 (8.559559, -81.1308434),
 (-5.6816069, 144.2489081),
 (-23.3165935, -58.1693445),
 (-6.8699697, -75.0458515),
 (12.7503486, 122.7312101),
 (52.215933, 19.134422),
 (40.0332629, -7.8896263),
 (25.3336984, 51.2295295),
 (45.9852129, 24.6859225),
 (64.6863136, 97.7453061),
 (-1.9646631, 30.0644358),
 (17.250512, -62.6725973),
 (13.8250489, -60.975036),
 (12.90447, -61.2765569),
 (43.9458623, 12.458306),
 (0.8875498, 6.9648718),
 (25.6242618, 42.3528328),
 (14.4750607, -14.4529612),
 (44.024322850000004, 21.07657433209902),
 (-4.6574977, 55.4540146),
 (8.6400349, -11.8400269),
 (1.3408630000000001, 103.83039182212079),
 (48.7411522, 19.4528646),
 (45.8133113, 14.4808369),
 (-8.7053941, 159.10710973724628),
 (8.3676771, 49.083416),
 (-28.8166236, 24.991639),
 (7.8699431, 29.6667897),
 (39.3262345, -4.8380649),
 (7.5554942, 80.7137847),
 (14.5844444, 29.4917691),
 (4.1413025, -56.0771187),
 (59.6749712, 14.5208584),
 (46.7985624, 8.2319736),
 (34.6401861, 39.0494106),
 (23.59829785, 120.83536313817521),
 (38.6281733, 70.8156541),
 (-6.5247123, 35.7878438),
 (14.8971921, 100.83273),
 (-8.5151979, 125.8375756),
 (8.7800265, 1.0199765),
 (10.8677845, -60.9821067),
 (33.8439408, 9.400138),
 (38.9597594, 34.9249653),
 (39.7837304, -100.4458825),
 (1.5333554, 32.2166578),
 (49.4871968, 31.2718321),
 (24.0002488, 53.9994829),
 (54.7023545, -3.2765753),
 (-32.8755548, -56.0201525),
 (41.32373, 63.9528098),
 (8.0018709, -66.1109318),
 (13.2904027, 108.4265113),
 (31.4331663, 34.3779285),
 (24.1188663, -13.950892328363645),
 (16.3471243, 47.8915271),
 (-14.5186239, 27.5599164),
 (-18.4554963, 29.7468414)]
In [39]:
df2['geo_loc']=lat_lon
df2.head()
Out[39]:
Country Confirmed Recovered Deaths geo_loc
0 Afghanistan 40687 34010 1507 (33.7680065, 66.2385139)
1 Albania 18556 10466 469 (41.000028, 19.9999619)
2 Algeria 55630 38788 1897 (28.0000272, 2.9999825)
3 Andorra 4038 2729 69 (42.5407167, 1.5732033)
4 Angola 8829 3384 265 (-11.8775768, 17.5691241)
In [40]:
type(lat_lon)
type(df2['geo_loc'][0])
Out[40]:
tuple
In [41]:
lat,lon=zip(*np.array(df2['geo_loc']))
In [42]:
type(lat)
Out[42]:
tuple
In [43]:
df2['lat']=lat
df2['lon']=lon
In [44]:
df2.head()
Out[44]:
Country Confirmed Recovered Deaths geo_loc lat lon
0 Afghanistan 40687 34010 1507 (33.7680065, 66.2385139) 33.768006 66.238514
1 Albania 18556 10466 469 (41.000028, 19.9999619) 41.000028 19.999962
2 Algeria 55630 38788 1897 (28.0000272, 2.9999825) 28.000027 2.999983
3 Andorra 4038 2729 69 (42.5407167, 1.5732033) 42.540717 1.573203
4 Angola 8829 3384 265 (-11.8775768, 17.5691241) -11.877577 17.569124
In [45]:
df2.drop('geo_loc', axis=1, inplace=True)
In [46]:
df2.head()
Out[46]:
Country Confirmed Recovered Deaths lat lon
0 Afghanistan 40687 34010 1507 33.768006 66.238514
1 Albania 18556 10466 469 41.000028 19.999962
2 Algeria 55630 38788 1897 28.000027 2.999983
3 Andorra 4038 2729 69 42.540717 1.573203
4 Angola 8829 3384 265 -11.877577 17.569124

Tileset

A tileset is a collection of raster or vector data broken up into a unifrom grid of square tiles.

  • A raster consists of a matrix of cells (or pixels) organized into rows and columns (or a grid) where each cell contains a value representing information.
  • Vector is a data structure, used to store spatial data. It is comprised of lines or arcs, defined by beginning and end points.

Marker

A marker identifies a location on a map.

How to plot markers on a Map.

  • You need to create a base map on which your markers will be placed.
  • And then, add your markers to it.
In [47]:
!pip install folium
Requirement already satisfied: folium in c:\users\pauli\anaconda3\lib\site-packages (0.11.0)
Requirement already satisfied: jinja2>=2.9 in c:\users\pauli\anaconda3\lib\site-packages (from folium) (2.11.2)
Requirement already satisfied: branca>=0.3.0 in c:\users\pauli\anaconda3\lib\site-packages (from folium) (0.4.1)
Requirement already satisfied: numpy in c:\users\pauli\anaconda3\lib\site-packages (from folium) (1.18.5)
Requirement already satisfied: requests in c:\users\pauli\anaconda3\lib\site-packages (from folium) (2.24.0)
Requirement already satisfied: MarkupSafe>=0.23 in c:\users\pauli\anaconda3\lib\site-packages (from jinja2>=2.9->folium) (1.1.1)
Requirement already satisfied: idna<3,>=2.5 in c:\users\pauli\anaconda3\lib\site-packages (from requests->folium) (2.10)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\pauli\anaconda3\lib\site-packages (from requests->folium) (1.25.9)
Requirement already satisfied: chardet<4,>=3.0.2 in c:\users\pauli\anaconda3\lib\site-packages (from requests->folium) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\pauli\anaconda3\lib\site-packages (from requests->folium) (2020.6.20)
In [48]:
import folium
folium.Map(location=[54,15], zoom_start=2)
Out[48]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [49]:
m = folium.Map(location=[54,15], tiles='openstreetmap', zoom_start=2)
for id,row in df2.iterrows():
    folium.Marker(location=[row['lat'],row['lon']], popup=row['Confirmed']).add_to(m)
m
Out[49]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [50]:
m = folium.Map(location=[54,15], tiles='openstreetmap', zoom_start=2)
for id,row in df2.iterrows():
    folium.Marker(location=[row['lat'],row['lon']], popup=row['Recovered']).add_to(m)
m
Out[50]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [51]:
m = folium.Map(location=[54,15], tiles='openstreetmap', zoom_start=2)
for id,row in df2.iterrows():
    folium.Marker(location=[row['lat'],row['lon']], popup=row['Deaths']).add_to(m)
m
Out[51]:
Make this Notebook Trusted to load map: File -> Trust Notebook

Marker cluster

Marker clusters can be a good way to simply a map containing many markers. When the map is zoomed out nearly markers are combined together into a cluster, which is separated out when the map zoom level is closer.

In [52]:
from folium.plugins import MarkerCluster
mc=MarkerCluster()
In [53]:
m = folium.Map(location=[54,15], tiles='openstreetmap', zoom_start=2)

for id,row in df2.iterrows():
    mc.add_child(folium.Marker(location=[row['lat'],row['lon']], popup=row['Confirmed']))
m.add_child(mc)    
m
Out[53]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [54]:
m = folium.Map(location=[54,15], tiles='openstreetmap', zoom_start=2)

for id,row in df2.iterrows():
    mc.add_child(folium.Marker(location=[row['lat'],row['lon']], popup=row['Recovered']))
m.add_child(mc)    
m
Out[54]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [55]:
m = folium.Map(location=[54,15], tiles='openstreetmap', zoom_start=2)

for id,row in df2.iterrows():
    mc.add_child(folium.Marker(location=[row['lat'],row['lon']], popup=row['Deaths']))
m.add_child(mc)    
m
Out[55]:
Make this Notebook Trusted to load map: File -> Trust Notebook

Geographic head map

Geographic heat maps are an interactive way to identify where something occurs , and demostrate areas of high and low density. Below is an exaample of a heat map showing the locations of Paul's Jr Restaurants. Read areas show where there are a high volume of Paul's Jr Restaurants in close proximity, while cooler areas show where there are fewer Paul's Jr Restaurants.

In [56]:
from folium.plugins import HeatMap
In [57]:
df2.head()
Out[57]:
Country Confirmed Recovered Deaths lat lon
0 Afghanistan 40687 34010 1507 33.768006 66.238514
1 Albania 18556 10466 469 41.000028 19.999962
2 Algeria 55630 38788 1897 28.000027 2.999983
3 Andorra 4038 2729 69 42.540717 1.573203
4 Angola 8829 3384 265 -11.877577 17.569124
In [58]:
m=folium.Map(location=[54,15], tiles='openstreetmap', zoom_start=2)
HeatMap(data=df2[['lat','lon','Confirmed']],radius=15).add_to(m)
m
Out[58]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [59]:
m=folium.Map(location=[54,15], tiles='openstreetmap', zoom_start=2)
HeatMap(data=df2[['lat','lon','Recovered']],radius=15).add_to(m)
m
Out[59]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [60]:
m=folium.Map(location=[54,15], tiles='openstreetmap', zoom_start=2)
HeatMap(data=df2[['lat','lon','Deaths']],radius=15).add_to(m)
m
Out[60]:
Make this Notebook Trusted to load map: File -> Trust Notebook